package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC539 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findMinDifference(List<String> timePoints) {
            int[] timeSlots = new int[timePoints.size()];
            int i = 0;
            for (String timePoint : timePoints) {
                timeSlots[i++] = Integer.parseInt(timePoint.split(":")[0]) * 60 + Integer.parseInt(timePoint.split(":")[1]);
            }

            Arrays.sort(timeSlots);
            int minInterval = Integer.MAX_VALUE;
            for (i = 0; i < timeSlots.length - 1; i++) {
                minInterval = Math.min(minInterval, timeSlots[i + 1] - timeSlots[i]);
            }

            int wholeDiff = timeSlots[timeSlots.length - 1] - timeSlots[0];
            minInterval = Math.min(minInterval, wholeDiff > 12 * 60 ? 24 * 60 - wholeDiff : wholeDiff);
            return minInterval;
        }
    }

    public void run() {
        Solution solution = new Solution();
        String[] li = InputUtil.toStringArray("[\"00:00\",\"23:59\",\"00:00\"]");
        System.out.println(solution.findMinDifference(new ArrayList<String>(Arrays.asList(li))));
    }

    public static void main(String[] args) throws Exception {
        LC539 an = new LC539();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
